package com.yjhb.android.sbz.v2.mvp.presenter

import com.alibaba.fastjson.JSONObject
import com.yjhb.android.sbz.entity.UserInfo
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.v2.mvp.V2ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.V2WxLoginView


/**
 *  创建者 zx
 *  创建时间 2021/8/6 9:22
 */
class V2WxLoginPresenter(v: V2WxLoginView) : V2ConventionPresenter<V2WxLoginView>(v) {


    fun verifyBindPhone(wxcode: String) {
        model?.let {
            HttpTool.request(it.verifyBindPhone(wxcode), object : HttpObserver<JSONObject?>() {
                override fun onResult(data: JSONObject?) {
                    data?.let { d ->
                        view?.telVerify(d.getString("phoneNo"), d.getString("openid"))
                    }
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }


    fun newWxLogin(openId: String, device: String) {
        view?.loggingIn()
        model?.let {
            HttpTool.request(it.wxLoginNew(openId, device), object : HttpObserver<UserInfo?>() {
                override fun onResult(data: UserInfo?) {
                    view?.onLoginSuccess(data)
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })

        }
    }

}